#include <Directory.h>
#include <CharDevice.h>
#include <BlockDevice.h>
#include <RegularFile.h>

bool Directory::mount(Filesystem *fs)
{
  bool toRet;
  if (mountpoint)
  {
    toRet = false;
  }
  else 
  {
    mountpoint = fs;
    mountpoint->getRoot()->setParentDir(this);
    toRet = true;
  }
}

u32int Directory::mknod(FileTypes type, char *name, u32int resourceId, u32int impl)
{
  DEBUG_MSG("mknod(" << hex << type << ", \"" << name << "\", " << resourceId << ", " << impl << ").");
  char *newname = NULL;
  if (name)
  {
    newname = new char[Kernel::strlen(name)+1];
    Kernel::strcpy(newname, name);
    newname[Kernel::strlen(name)] = '\0';
  }
  
  File *tmp;
  switch(type)
  {
    case eFileType_Directory:
      tmp = new Directory(newname, parent, resourceId);
      break;
    case eFileType_CharDevice:
      tmp = new CharDevice(newname, parent, resourceId);
      break;
    case eFileType_BlockDevice:
      tmp = new BlockDevice(newname, parent, resourceId);
      break;
    case eFileType_Symlink:
    case eFileType_RegularFile:
      tmp = new RegularFile(newname, parent, resourceId);
      break;
  }
  tmp->setImplDefined(impl);
  if (name)
  {
    addEntry(tmp);
  }
  return tmp->resource->getId();
}
